home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SOURCE.ZIP / DOORS.ASM < prev    next >
Assembly Source File  |  1986-06-05  |  7KB  |  152 lines

  1. title   DOORS.ASM - Switch Color/Mono Screens On Keyboard Request
  2. ;
  3. VECTORS         segment at 0h           ; 8088 / 80286 Interrupt Vector Area
  4.         org     9h*4                    ; IBM PC Keyboard is Int 9H
  5. KB_INT_VECTOR   label   dword           ; Double word label
  6. ;
  7. VECTORS         ends
  8. ;
  9. ROM_BIOS_DATA   segment at 40h          ; Low Memory "BIOS" Parameters
  10. ;
  11.         org     10h                     ; Location of EQUIP_FLAG
  12. EQUIP_FLAG      dw      ?               ; Contains video settings
  13.                                         ; in bits 4 and 5
  14. ;
  15.         org     17h                     ; Location of KB_FLAG
  16. KB_FLAG         db      ?               ; Contains Alt (bit 3) &
  17.                                         ; Right Shift (bit 0) States
  18. ROM_BIOS_DATA   ends
  19. ;
  20. ; Initialization Routine
  21. ;
  22. CODE_SEG        segment
  23.         assume  cs:CODE_SEG
  24.         org     100h                    ; COM program format
  25. BEGIN:  jmp     SWAP_VECTORS            ; Initialize vectors and attach to DOS
  26. ;
  27. ROM_KB_INT      dd      0               ; Double word to save address of
  28.                                         ; ROM-BIOS keyboard interrupt
  29. ; DOORS_INT intercepts the keyboard interrupt and switches
  30. ;      screens if [Alt]-[Right Shift] combination is pressed
  31. ;
  32. DOORS_INT       proc    near
  33.         assume  ds:nothing
  34.         push    ds                      ; Push all affected registers
  35.         push    es
  36.         push    ax
  37.         push    bx
  38.         push    cx
  39.         push    dx
  40.         push    si
  41.         push    di
  42. ;
  43.         pushf                           ; Push Flags for fake interrupt call
  44.         call    ROM_KB_INT              ; to BIOS program to read keyboard
  45. ;
  46.         assume  ds:ROM_BIOS_DATA        ; Define data segment to read
  47.         mov     ax,ROM_BIOS_DATA        ; keyboard flag & equipment flag
  48.         mov     ds,ax
  49.         mov     al,KB_FLAG              ; Get keyboard flag
  50.         and     al,09h                  ; Isolate [Alt] + [Right Shift]
  51.         cmp     al,09h                  ; Are they pressed?
  52.         jne     RETURN                  ; No, quit
  53. ;
  54. ; [Alt] + [Right Shift] are pressed -- Continue processing
  55. ; Check on video mode - quit if not monochrome, color 80x25 or BW 80x25
  56. ;
  57.         mov     ah,15                   ; Call Func 15 of Int 10h to
  58.         int     10h                     ; get video state of the PC
  59.         cmp     al,7                    ; Is screen monochrome?
  60.         je      SCREEN_OKAY             ; Yes, go switch screens
  61.         cmp     al,3                    ; Is screen color text?
  62.         jbe     CHECK_40_OR_80          ; Yes, go check for 80 or 40 char
  63.         jmp     RETURN                  ; Screen is in graphics mode, quit
  64. CHECK_40_or_80:
  65.         cmp     al,1                    ; Is screen 40-character?
  66.         jbe     RETURN                  ; Yes, quit
  67. ;
  68. SCREEN_OKAY:
  69. ;
  70. ; Save the current cursor position
  71. ;
  72.         mov     ah,3                    ; Call Func 3 of Int 10H
  73.         mov     bh,0                    ; to read cursor position
  74.         int     10h                     ; (page zero for color screen)
  75. ;
  76. ; Screen switch routine - Establish calling argument (AL) for Int 10h
  77. ;
  78.         mov     bx,EQUIP_FLAG           ; Current equipment flag to BX
  79.         mov     cx,bx                   ; Make a copy of it in CX
  80.         and     cx,30h                  ; Extract screen information
  81.         xor     bx,cx                   ; Erase current screen information in BX
  82.         or      bx,20h                  ; Set BX to color 80x25
  83.         mov     al,3                    ; Set AL for color 80x25 in Int 10h
  84.         cmp     cx,30h                  ; Is current mono?
  85.         je      SET_MODE                ; Yes, switch to color
  86.         or      bx,30h                  ; No, set BX for monochrome
  87.         mov     al,7                    ; Set AL for monochrome in Int 10h
  88. SET_MODE:
  89.         mov     EQUIP_FLAG,bx           ; Write BX to equipment flag
  90.         xor     ah,ah                   ; Use Func 0 of Int 10h to
  91.         int     10h                     ; change screen parameters
  92. ;
  93. ; Restore Cursor
  94. ;
  95.         mov     ah,2                    ; Use Func 2 of Int 10h to restore
  96.         mov     bh,0                    ; cursor on new screen (position in DX)
  97.         int     10h
  98. ;
  99. ; After screens are switched, set DS and ES registers to move screen data
  100. ;
  101.         mov     ax,0b000h               ; Load ES with Mono Segment
  102.         mov     es,ax
  103.         mov     ax,0b800h               ; Load DS with Color Segment
  104.         mov     ds,ax
  105.         cmp     cx,30h                  ; Did we switch from mono?
  106.         jne     COPY_THE_SCREEN         ; Yes, move data from mono to color
  107.         push    ds                      ; No, swap ES and DS to move data
  108.         push    es                      ; from color to mono
  109.         pop     ds
  110.         pop     es
  111. COPY_THE_SCREEN:
  112.         xor     di,di                   ; Start at zero offsets
  113.         xor     si,si
  114.         mov     cx,2000                 ; 2000 chars + attrs per screen
  115.         cld                             ; Make sure move is 'forward'
  116. rep     movsw                           ; Move Words with string instruction
  117. ;
  118. RETURN:
  119.         pop     di                      ; Restore saved registers
  120.         pop     si
  121.         pop     dx
  122.         pop     cx
  123.         pop     bx
  124.         pop     ax
  125.         pop     es
  126.         pop     ds
  127.         iret                            ; Return to system
  128.  
  129. DOORS_INT       endp
  130. ;
  131. ; This procedure initializes the new keyboard interupt vectors
  132. ;
  133. SWAP_VECTORS    proc    near
  134.         assume  ds:VECTORS
  135.         mov     ax,VECTORS                      ; Set up the data
  136.         mov     ds,ax                           ; segment for vectors
  137.         cli                                     ; Disable interrupts
  138.         mov     ax,word ptr KB_INT_VECTOR       ; Store addresses
  139.         mov     word ptr ROM_KB_INT,ax          ; of BIOS program
  140.         mov     ax,word ptr KB_INT_VECTOR[2]
  141.         mov     word ptr ROM_KB_INT[2],ax
  142.         mov     word ptr KB_INT_VECTOR, offset DOORS_INT ; Substitute Our
  143.         mov     word ptr KB_INT_VECTOR[2],cs             ; Program
  144.         sti                                     ; Enable interrupts
  145.         mov     dx,offset SWAP_VECTORS          ; End of new resident
  146.                                                 ; program
  147.         int     27h                             ; Terminate resident
  148. SWAP_VECTORS    endp
  149. CODE_SEG        ends
  150.         end     BEGIN
  151. ;
  152.